package com.example.italkapp2.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;

import androidx.annotation.Nullable;

@SuppressLint("AppCompatCustomView")
public class RoundCornerImageView extends ImageView {

    protected float radius;

    public RoundCornerImageView(Context context) {
        super(context);
    }

    public RoundCornerImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RoundCornerImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        Path path = new Path();
        int width = this.getWidth();
        int height = this.getHeight();
        this.radius = Math.max(width, height);
        path.addRoundRect(new RectF(0,0,width,height),radius,radius,Path.Direction.CW);
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
}
